﻿@using Kendo.Mvc.UI;


@{
    ViewBag.Title = "Thêm/Sửa Quyền";
}
@{
    AjaxOptions aj = new AjaxOptions
    {
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "content-main",
        LoadingElementId = "loading-icon",
        OnFailure = "AjaxFailure",
        OnBegin = "AjaxBegin",
        OnComplete = "AjaxComplete"
    };
}
@model List<TS2015.Models.TbChucNang>
@using (@Html.BeginForm("AddActing", "AccoutManagement", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
@*<link href="~/Content/Treecheckbox/css/Tree.css" rel="stylesheet" />*@

<section class="panel">
    <header class="panel-heading">
        <h4 style="margin:0">Thêm quyền</h4>
    </header>
    <div class="panel-body">
        <div class="table-responsive">
            <div class="form-group">
                <div class="col-lg-6 col-md-6 row">
                    <strong class="col-lg-3 col-md-3 row">Tên quyền:</strong>
                    <div class="col-lg-6 col-md-6 row">
                        @if (ViewBag.IDRequest != null)
                        {
                            @Html.TextBox("txtActing", (string)ViewBag.Acting, new { @class = "form-control", disabled = "disabled" })
                            <input type="hidden" name="MyActing" value="@ViewBag.Acting" />
                        }
                        else
                        {
                            @Html.TextBox("txtActing", "", new { @class = "form-control valid", data_val = "true", data_val_required = " ", id = "txtActing", aria_required = "true", aria_invalid = "true", aria_describedby = "txtActing-error" })
                        }
                        @Html.ValidationMessage("txtActing")
                    </div>
                </div>
                @*<div class="col-lg-6 col-md-6 row">
                    <strong class="col-lg-3 col-md-3 row">Trạng thái:</strong>
                    <div class="col-lg-6 col-md-6 row">
                        @Html.DropDownList("TrangThai", (SelectList)ViewBag.TrangThai, "Chọn trạng thái", new { @class = "form-control"})
                    </div>
                </div>*@
            </div>
            <div style="clear:both"></div><br />
            <div class="form-group">
                <div class="col-lg-3 col-md-3 row">
                    <strong>Chức năng: </strong>
                    
                </div>
                <div style="clear:both"></div><br />
                <div class="col-lg-12 col-md-12 row">
                    <div class="treeview-back">
                        
                        @(Html.Kendo().TreeView()
                            .Name("treeview")
                            .Checkboxes(checkboxes => checkboxes
                                .Name("checkedFiles")
                                .CheckChildren(true)
                            )
                            
                            .Items(treeview =>
                            {
                                 //int count = 0;
                                foreach (var parent in Model)
                                {
                                    if (parent.MaCNCha == 0)
                                    {
                                        //count = count + 1;
                                        treeview.Add().Text(parent.TenCN).Id(parent.MaCN.ToString())
                                        .Expanded(true)
                                            //.SpriteCssClasses("folder")

                                        .Items(project =>
                                        {
                                            foreach (var item in Model.Where(m => m.MaCNCha > 0))
                                            {
                                                if (item.MaCNCha == parent.MaCN)
                                                {
                                                    project.Add().Text(item.TenCN).Id(item.MaCN.ToString());
                                                }
                                            }
                                        });
                                    }
                                }
                            })
                            .ItemAction(item =>
                            {
                                if(ViewBag.Funtion == null)
                                {
                                    item.Checked = false;
                                }
                                else
                                {
                                    item.Checked = ((int[])ViewBag.Funtion).Contains(int.Parse(item.Id));
                                }
                            })
                        )
                        @Html.ValidationMessage("treeview")
                    </div>
                </div>
            </div>
            <div style="clear:both"></div>
            <div class="form-group">
                <div class="col-lg-12 col-md-12">
                    <div class="toolbar" style="float:right">
                        @if (ViewBag.IDRequest != null)
                        {
                            <button class="btn btn-primary btn-primary-registration" type="submit"><b>Sửa</b></button>
                        }
                        else
                        {
                            <button class="btn btn-primary btn-primary-registration" type="submit"><b>Thêm mới</b></button>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
}
@*@section Scripts{
    <script>
        $(document).ready(function () {
            $(".treeview li>ul").css('display', 'none'); // Hide all 2-level ul
            $(".collapsible").click(function (e) {
                e.preventDefault();
                $(this).toggleClass("collapse expand");
                $(this).closest('li').children('ul').slideToggle();
            });
        });
        
    </script>
}*@


@*<script src="~/Content/Treecheckbox/jquery.nestable.js"></script>
    <script src="~/Content/Treecheckbox/jquery.sortable.js"></script>

    <script src="~/Content/Treecheckbox/sortable.js"></script>*@